﻿using System.Collections.Generic;
using System.Linq;
using Common.Dao;
using Common.Dao.EsDao;
using Common.Extension;
using Common.Model;
using log4net;

namespace Script.Script
{
    public class SyncEsScript
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(SyncEsScript));

        public static void Run()
        {
            Log.Info("SyncEsScript start");
            int pageSize = 500;
            int page = 0;

            Log.Info("sync company_notice");
//            int count = CompanyNoticeDao.Count();
//
//            for (; page * pageSize < count; page++)
//            {
//                //分页获取公告
//                List<CompanyNotice> companyNotices = CompanyNoticeDao.GetAll(pageSize, page);
//                //Es存储剩余未存储的公告
//                if (companyNotices.Any())
//                {
//                    CompanyNoticeEsDao.SaveCompanyNotices(companyNotices);
//                }
//            }

            Log.Info("sync question_answer");

            var qAnswers = QuestionAnswerDao.GetAll();
            var qAnswersList = qAnswers.Partition(5000).ToList();
            foreach (var answers in qAnswersList)
            {
                QuestionAnswerEsDao.SaveQuestionAnswer(answers);
            }

            Log.Info("SyncEsScript end");
        }
    }
}
